<%
/*Auther name      : Frederic Anand
  file name        : 500.jsp
  date modified    : 17-Feb-2009
  revision history :
*/
%>
<%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %>
<jsp:include page="top.jsp"/><link href="../css/sample1.css" rel="stylesheet" type="text/css">
<script>
function changeStatus()
{
	if(document.getElementById('listPict').checked) {
		document.getElementById('listPict').value = "on";
	} else {
		document.getElementById('listPict').value = "off";
	}

}
function goBack() {
	var url;
	<%
		String cnt = (String) session.getAttribute("back");
		if("index".equals(cnt)) {
	%>
			url = "../portal/index.do";
	<%
		} else {
	%>
			url = "../jsp/SearchClassifieds.jsp?PostingType=" + "<%=request.getParameter("PostingType")%>";
			<%
				if(null!=request.getParameter("CatType")) {
			%>
				url = url + "&CatType=" + "<%=request.getParameter("CatType")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("pricemin")) {
			%>
				url = url + "&pricemin=" + "<%=request.getParameter("pricemin")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("pricemax")) {
			%>
				url = url + "&pricemax=" + "<%=request.getParameter("pricemax")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("excludeSearchContent")) {
			%>
				url = url + "&excludeSearchContent=" + "<%=request.getParameter("excludeSearchContent")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("adContent")) {
			%>
				url = url + "&adContent=" + "<%=request.getParameter("adContent")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("City")) {
			%>
				url = url + "&City=" + "<%=request.getParameter("City")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("Place")) {
			%>
				url = url + "&Place=" + "<%=request.getParameter("Place")%>";
			<%
				}
			%>
			<%
				if(null!=request.getParameter("listPict")) {
			%>
				url = url + "&listPict=" + "<%=request.getParameter("listPict")%>";
			<%
				}
			%>
	<%
		}
	%>

	window.location.href = url;
}
</script>
<SCRIPT LANGUAGE="JavaScript">
	function checkNum(fieldName, fieldVal, fieldLen)
	{
		//Check whether the value of the field is a number
		if (isNaN(fieldVal)==true || (fieldLen!=fieldVal.length && fieldLen!=0))
		{       
			if (fieldLen==0)
			{
				document.form1.elements[fieldName].focus();
				alert("This must be a number.");			
				return false;
			}
			else
			{
				document.form1.elements[fieldName].focus();
				alert("This must be a " + fieldLen + " digit number.");
				return false;
			}
		}
	}
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<comment><br><br></comment>
<br>
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<img src="../images/classifieds_n_tab.gif" width="720" height="76" border="0" usemap="#Map">
		</td>
	</tr>
	<tr>
		<td class="b0rdersgif">
			<table width="680" border="0" align="center" cellpadding="0" cellspacing="0" >
				<tr>
					<td colspan="5">
						<%
						java.util.Hashtable allArea = (java.util.Hashtable)application.getAttribute("APALLCATEGORY");
						java.util.Hashtable allAreaId = (java.util.Hashtable)application.getAttribute("APCATIDS");
						String catType =request.getParameter("CatType");
						session.setAttribute("CatType",catType);
						int catId;
						String mainCatId;
						String subCatName;
						String mainCatName="";
						int postingID=0;
						
						if (catType!=null)
						{
							catId =  Integer.parseInt(catType);
						} 
						else 
						{
							catId=0;
						}
							if (catId==0)
							{
								subCatName="";
								mainCatId = request.getParameter("PostingType");
								if (mainCatId!=null && mainCatId.length()>0)
								{
									postingID = Integer.parseInt(mainCatId);
								}
									session.setAttribute("PostingType",mainCatId);
								
									if (mainCatId.equals("99"))
									{
										mainCatName="All Categories";
									}
									else
									{
										mainCatName = (String)allArea.get(mainCatId);
									}
							}
							else
							{
								mainCatId = (String)allAreaId.get(catId+"");
								subCatName = (String)allArea.get(catId+"");
								mainCatName = (String)allArea.get(mainCatId);
							}
							%>
						<form name="form1" method="post" action="../portal/SearchAdv.do?action=SearchAd&PostingType=<%=mainCatId%>&CatType=<%=catId%>">
							<table width="100%" cellpadding="3" cellspacing="0" border="0" class="tablebgc02">
							<!--DWLayoutTable-->
								<tr class="trbgc01">
									<td valign="top" colspan="6" class="title" height="24" nowrap>
										<% if (mainCatName.equals("All Categories"))
										   {
											mainCatName="";
										%>
											<font size="3"><font  class="boldtext whitee">Search
											all Categories: </font><b><font ></font></b></font>
										<% } 
										   else 
										   {   
										%>
											<font size="3"><font  class="boldtext whitee">Search
											in this Category: </font><b><font ></font></b></font>
										<% }%>
									</td>
								</tr>
											<%
											String pricemin = request.getParameter("pricemin");
											
											if (pricemin==null)
												pricemin="";
												session.setAttribute("pricemin",pricemin);
												String pricemax = request.getParameter("pricemax");
												
											if (pricemax==null)
												pricemax="";
												session.setAttribute("pricemax",pricemax);
												String adContent = request.getParameter("adContent");
												String excludeSearchContent= request.getParameter("excludeSearchContent");
											if (adContent==null)
												adContent="";
												session.setAttribute("adContent",adContent);
												
											if (excludeSearchContent==null)
												excludeSearchContent="";
												session.setAttribute("excludeSearchContent",excludeSearchContent);
												session.setAttribute("City", request.getParameter("City"));
												session.setAttribute("listPict",request.getParameter("listPict"));
											%>
							<% if (mainCatId.equals("1") || mainCatId.equals("2")) 
						   {%>
								<tr bgcolor="#FFFFFF">
									<td height="28" align="right" nowrap class="text">Price Min:</td>
									<td width="144">
										<input type="text" name="pricemin"  value="<%=pricemin%>"  onchange="return checkNum('pricemin', pricemin.value, 0)">
									</td>
									<td width="100" nowrap class="text">Price Max:</td>
									<td colspan="3">
										<input type="text" name="pricemax"  value="<%=pricemax%>" onBlur="return checkNum('pricemax', pricemax.value, 0)">
									</td>
								</tr>
						<% }%>
								<tr bgcolor="#FFFFFF">
									<td height="28" align="right" nowrap class="text">Search Words:</td>
									<td>
										<input type="text" name="adContent" value="<%=adContent%>">
									</td>
									<td align="right"><span class="text">Exclude Words:</span></td>
									<td colspan="2"><input name="excludeSearchContent" type="text" id="excludeSearchContent" value="<%=excludeSearchContent%>">
									</td>
									<td>&nbsp;
									</td>
								</tr>
								<tr bgcolor="#FFFFFF">
									<td valign="top" class="text">City</td>            
									<td>
										<select name="City">	                    
										<option value="0">All</option>
											<%							
											java.sql.Connection conn = null;
											java.sql.Statement  stat = null;
											int city_id = 0;
											if(null != request.getParameter("city_id") && !"".equals(request.getParameter("city_id"))) 
											{
												city_id = Integer.parseInt(request.getParameter("city_id"));
											}	
											Class.forName("com.mysql.jdbc.Driver");
											conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/ba3602_droikclassifieds","ba3602_portal", "p0rtal");
											//conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/ba3602_droikclassifieds","root","" );
											stat = conn.createStatement();	  
											java.sql.ResultSet rs = stat.executeQuery("select city_id, cityname from lookup_city;");
											int cityid;
											String cityname;
											while (rs.next()) 
											{
												cityid = rs.getInt(1);
												cityname = rs.getString(2);
											%>
												<option <%if(city_id==cityid) out.println("selected");%> value="<%=cityid%>"><%=cityname%></option>
											<%
											}
											%>
										</select> 
									</td>
									<td class="text">With Pic
									<%
										if("on".equals(request.getParameter("listPict"))) 
										{
									%>
											<input type="checkbox" checked name="listPict" onClick="javascript:changeStatus()">
									<%
										} 
										else 
										{
									%>
											<input type="checkbox" name="listPict" onClick="javascript:changeStatus()">
									<%
										}
									%>
									</td>
									<td align="right" valign="top">
										<input name="Search" type="submit" value="Search">
									</td>
									<td width="84">&nbsp;</td>
									<td>&nbsp;</td>
								</tr>
								<tr bgcolor="#FFFFFF">
									<td height="47" colspan="6" nowrap class="title"><br>
									<%=mainCatName%><font size="1"><b> <img src="../images/arrow.gif" width="13" height="13"></b></font><%=subCatName%>
									</td>
								</tr>
						<% if (mainCatId.equals("1") || mainCatId.equals("2")) 
						   {%>
							<%if (catType==null || catType.equals("0"))
							  {%>
								<tr bgcolor="#FFFFFF">
									<td colspan="6" valign="top"  height="44">
									<br><display:table width="100%" cellpadding="4" cellspacing="1" border="1" class="simple" name="sessionScope.SEARCHRESULT" pagesize="50">
									<display:column property="datePosted" title="Posted On" sortable="true" headerClass="title_link" group="1" />
									<display:column property="adTitle" title="Featured Postings" href="../portal/postadv.do?action=DisplayAd" paramId="advId" paramProperty="advId" sortable="true" headerClass="title_link"/>
									<display:column property="price" title="Price" sortable="true" headerClass="title_link"/>
									<display:column property="subCategoryName" title="Sub-Category" sortable="true" headerClass="title_link" />
									<display:column property="city" title="Place" sortable="true" headerClass="title_link" />
									</display:table></td>
								</tr>
							<%}
							  else
							  {%>
								<tr bgcolor="#FFFFFF">
									<td colspan="6" valign="top"  height="44">
									<br><display:table width="100%" cellpadding="4" cellspacing="1" border="1" class="simple" name="sessionScope.SEARCHRESULT" pagesize="50">
									<display:column property="datePosted" title="Posted On" sortable="true" headerClass="title_link" group="1" />
									<display:column property="adTitle" title="Featured Postings" href="../portal/postadv.do?action=DisplayAd" paramId="advId" paramProperty="advId" sortable="true" headerClass="title_link"/>
									<display:column property="price" title="Price" sortable="true" headerClass="title_link"/>
									<display:column property="city" title="Place" sortable="true" headerClass="title_link" />
									</display:table></td>
								</tr>
							<%}
						   } 
						   else 
						   {%>
						<% 	if (catType==null)
						 	{%>
								<tr bgcolor="#FFFFFF">
									<td colspan="6" valign="top"  height="25"> <display:table width="100%" cellpadding="4" cellspacing="1" border="1" class="simple" name="sessionScope.SEARCHRESULT" pagesize="50" >
									<display:column property="datePosted" title="Posted On" sortable="true" headerClass="title_link" group="1"/>
									<display:column property="adTitle" title="Featured Postings" href="../portal/postadv.do?action=DisplayAd" paramId="advId" paramProperty="advId" sortable="true" headerClass="title_link"/>
									<display:column property="subCategoryName" title="Sub-Category" sortable="true" headerClass="title_link" />
									<display:column property="city" title="Place" sortable="true" headerClass="title_link" />
									</display:table></td>
								</tr>
							<%
							}
							else
							{%>
								<tr bgcolor="#FFFFFF">
									<td colspan="6" valign="top"  height="25"> <display:table width="100%" cellpadding="4" cellspacing="1" border="1" class="simple" name="sessionScope.SEARCHRESULT" pagesize="50" >
									<display:column property="datePosted" title="Posted On" sortable="true" headerClass="title_link" group="1"/>
									<display:column property="adTitle" title="Featured Postings" href="../portal/postadv.do?action=DisplayAd" paramId="advId" paramProperty="advId" sortable="true" headerClass="title_link"/>
									<display:column property="city" title="Place" sortable="true" headerClass="title_link" />
									</display:table></td>
								</tr>
							<%
							}
						   }%>
								<tr>
									<td height="0" width="103"></td>
									<td width="144"></td>
									<td></td>
									<td width="54"></td>
									<td></td>
									<td width="159"></td>
								</tr>
								<tr bgcolor="#FFFFFF">
									<td  colspan="6" align="right">
										<input class="button" type="button" name="Back" value="Back" onClick="javascript:goBack();"  />
									</td>
								</tr>
							</table>
						</form>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td><img src="../images/border_bot2.gif" width="719" height="20"></td>
	</tr>
</table>
<br>
<br>
<jsp:include page="footer.html"/>
<jsp:include page="map.html"/>	
</body>
</html>
